package com.wh1200.mybatis.xmlless.model

import com.wh1200.mybatis.xmlless.AnnotatedElementDetailInfo


/**
 *
 * @author 吴昊
 * @date 2023/12/19 16:19
 * @since v4.0.0
 * @version 1.0
 */
data class XmllessTableInfo(
    val keyProperty: String?,
    val keyColumn: String?,
    val tableName: String,
    val entityTypeName: String,
    /** 所有表字段信息 */
    val tableFields: List<XmllessTableFieldInfo>,
    /** 表字段信息map，key为对应实体类的属性名称 */
    val tableFieldMap: Map<String, XmllessTableFieldInfo>,
    /** 逻辑删除字段信息 */
    val logicDeleteFieldInfo: XmllessTableFieldInfo?,
    /** 所有类字段信息 */
    val classFields: List<AnnotatedElementDetailInfo>
) {

  /** schema */
  val schema: String?

  /** 不含schema的表名称 */
  val simpleTableName: String?

  init {
    val nameParts = tableName.split(".")
    schema = if (nameParts.size == 2) {
      nameParts[0]
    } else {
      null
    }
    simpleTableName = if (nameParts.size == 2) {
      nameParts[1]
    } else {
      tableName
    }
  }

}
